package java6681.sort.list;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.util.*;

/**
 * @author Junichiro
 * @description test
 * @date 2021-04-06 0:46
 **/

public class test {
    public static void main(String[] args) {
        /*使用自然排序 按成绩降序*/
        List<Course6681> list = new ArrayList<>();

        /*使用比较器排序 按学期升序*/
        List<Course6681> list2 = new ArrayList<>();

        /*使用比较器排序 按学分升序 */
        List<Course6681> list3 = new ArrayList<>();

        /*按学期、学分多关键字排序（升序）*/
        List<Course6681> list4 = courseList();
        System.out.println("----按学期、学分多关键字排序（升序）----");
        for (Course6681 course6681 : list4) {
            System.out.println(course6681);
        }

        Course6681 c1 = new Course6681("Java", 4, 89, "1上", "A001");
        Course6681 c2 = new Course6681("Python", 2, 92, "2上", "A002");
        Course6681 c3 = new Course6681("C++", 2, 78, "2下", "A003");
        Course6681 c4 = new Course6681("HTML+CSS", 2, 69, "3上", "A004");
        Course6681 c5 = new Course6681("计算机网络", 3, 79, "1下", "A005");

        list.add(c1);
        list.add(c2);
        list.add(c3);
        list.add(c4);
        list.add(c5);

        list2.add(c1);
        list2.add(c2);
        list2.add(c3);
        list2.add(c4);
        list2.add(c5);

        list3.add(c1);
        list3.add(c2);
        list3.add(c3);
        list3.add(c4);
        list3.add(c5);


        Collections.sort(list3, new SorterByCredit6681());
        System.out.println("---------学分升序----------");
        for (Course6681 course6681 : list3) {
            System.out.println(course6681);
        }

        System.out.println("------学期升序------");
        Collections.sort(list2, new Comparator<Course6681>() {
            @Override
            public int compare(Course6681 c1, Course6681 c2) {
                String cSb1 = c1.getTerm().substring(0, 1);
                String cSb2 = c2.getTerm().substring(0, 1);
                int num = Integer.parseInt(cSb1) - Integer.parseInt(cSb2);
                int num2 = num == 0 ? c1.getTerm().substring(1, 2).compareTo(c2.getTerm().substring(1, 2)) : num;
                return num2;
            }
        });
        for (Course6681 course6681 : list2) {
            System.out.println(course6681);
        }

        System.out.println("-----成绩降序------");
        Collections.sort(list);
        for (Course6681 course6681 : list) {
            System.out.println(course6681);
        }

    }

    public static List<Course6681> courseList() {
        List<Course6681> list = new ArrayList<>();
        Course6681 c1 = new Course6681("Java", 3, 89, "1下", "A001");
        Course6681 c2 = new Course6681("Python", 2, 92, "2上", "A002");
        Course6681 c3 = new Course6681("C++", 2, 78, "2下", "A003");
        Course6681 c4 = new Course6681("HTML+CSS", 2, 69, "3上", "A004");
        Course6681 c5 = new Course6681("计算机网络", 4, 79, "1上", "A005");

        list.add(c1);
        list.add(c2);
        list.add(c3);
        list.add(c4);
        list.add(c5);

        Collections.sort(list, new Comparator<Course6681>() {
            @Override
            public int compare(Course6681 c1, Course6681 c2) {
                String cSb1 = c1.getTerm().substring(0, 1);
                String cSb2 = c2.getTerm().substring(0, 1);
                int num = Integer.parseInt(cSb1) - Integer.parseInt(cSb2);
                int num2 = num == 0 ? c1.getTerm().substring(1, 2).compareTo(c2.getTerm().substring(1, 2)) : num;
                int num3 = num2 == 0 ? c1.getCredit() - c2.getCredit() : num2;
                return num3;
            }
        });
        return list;
    }
}
